<?php

/**
 * Classe para manipulação de plugins
 */
class pTray_Plugin_Abstract {
	/**
	 * Armazena o objeto principal
	 * 
	 * @access private
	 * @var array
	 */
	private $_main;
	
	/**
	 * Construtor
	 */
	final public function __construct($main) {
		$this->_main = $main;
		
		// Inicia a configuração
		$this->load();
	}
	
	/**
	 * Adiciona um submenu ao menu global
	 * 
	 * @param string $title Titulo do submenu
	 * @return Fabula::GtkMenu
	 */
	final public function append_menu($title, $icon=NULL) {
		
		// Cria o item
		$menuitem = Fabula::GtkMenuItem($title);
		
		if(!is_null($icon)) {
			if(file_exists($icon)) {
				$image = GtkImage::new_from_file($icon);
			}
			else {
				$image = GtkImage::new_from_stock($icon, Gtk::ICON_SIZE_MENU);
			}
			$filho = $menuitem->child;
			$menuitem->remove($filho);
			$menuitem->add($box=Fabula::GtkHBox());
			$box->pack_start($image, FALSE);
			$box->pack_start(Fabula::GtkLabel(" " . $title), TRUE);
		}
		
		// Adiciona o item ao menubar
		$this->_main->widgets['mnuMain']->append($menuitem);
		
		// Cria o menu
		$menu = Fabula::GtkMenu();
		
		// Adiciona o menu ao item
		$menuitem->set_submenu($menu);
		
		// Atualiza o widget
		$this->_main->widgets['mnuMain']->append(new GtkSeparatorMenuItem());
		$this->_main->widgets['mnuMain']->show_all();
		
		// Retorna o menu
		return $menu;
		
		//return $this->_main->widgets['mnuMain']->append_menu($title);
	}
}
